//
// Created by TianBo on 2022/6/1.
//

#include "iostream"

using namespace std;

class Solution {
public:
    int countDigitOne(int n) {
        long long m = 1;
        int res = 0;
        for (int k = 0; n >= m; ++k) {
            int extra;
            if(n % (m * 10) < m)
                extra = 0;
            else if(n % (m * 10) >= m && n % (m * 10) < 2*m)
            {
                extra = n % (m * 10) - m + 1;
            }
            else
                extra = m;
            res += (n / (m * 10) * m + extra);
            m *= 10;
        }
        return res;
    }
};

int main()
{
    int n = 999;
    Solution s;
    cout<<s.countDigitOne(n)<<endl;
    return 0;
}